package se.slackers.automatunes.ui;

import java.awt.FlowLayout;

import javax.swing.BorderFactory;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;

@SuppressWarnings("serial")
public class ParameterJPanel extends JPanel {
	private final String name;

	public ParameterJPanel(final String name) {
		this.name = name;

		final int S = 5;
		setBorder(BorderFactory.createEmptyBorder(S, S, S, S));
		setLayout(new VerticalFlowLayout(VerticalFlowLayout.TOP, S, S));
	}

	public final ParameterJPanel display(final ParameterSet parameters) {
		removeAll();
		final JLabel title = new JLabel(name, JLabel.CENTER);
		add(title);

		for (final Parameter<?, ?> parameter : parameters.collection()) {
			final JComponent component = parameter.create();
			final JLabel label = new JLabel(parameter.name());

			label.setToolTipText(parameter.tooltip());

			final JPanel row = new JPanel(new FlowLayout(FlowLayout.LEFT, 5, 5));
			row.add(label);
			row.add(component);

			add(row);
		}

		return this;
	}
}
